//
//  FMAwardsView.m
//  大转盘
//
//  Created by Annie on 2020/6/1.
//  Copyright © 2020 Annie. All rights reserved.
//

#import "FMAwardsView.h"
#import "FMAwardsModel.h"

#define kGGRandomColor [UIColor colorWithRed:random()%256/255.0 green:random()%256/255.0 blue:random()%256/255.0 alpha:1.0]


@interface FMAwardsView ()
@property (nonatomic, strong) UILabel *label;
@end

@implementation FMAwardsView

- (void)setModel:(FMAwardsModel *)model{
    _model = model;
    self.label.text = model.title;
    
    [self setNeedsDisplay];
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.label];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.label.frame = self.bounds;
}


- (void)drawRect:(CGRect)rect {
    
    [super drawRect:rect];
    
    CGPoint startPoint = CGPointMake(0, rect.size.height * 0.5);
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:startPoint];
    
    [path addArcWithCenter:startPoint radius:self.model.radius startAngle:-self.model.angle * 0.5 endAngle:self.model.angle * 0.5 clockwise:YES];
    [path closePath];
    
//    [path addLineToPoint:CGPointMake(rect.size.width, 0)];
//    [path addLineToPoint:CGPointMake(rect.size.width, rect.size.height)];
    
    [kGGRandomColor setStroke];
    [path stroke];
    
    

    [kGGRandomColor setFill];
    [path fill];
}

- (UILabel *)label{
    if (!_label) {
        UILabel *view = [UILabel new];
        view.textAlignment = NSTextAlignmentCenter;
        _label = view;
    }
    return _label;
}
@end
